package br.ufal.questione.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;



@Entity
@Table(schema = "questione", name = "pergunta")
public class Pergunta implements Serializable {

	private static final long serialVersionUID = 4053239137805860463L;

	@Id
	@SequenceGenerator(name = "sequence-generator", sequenceName = "questione.pergunta_ID_seq", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence-generator")
	@Column(name = "id")
	private Long id;

	@ManyToOne
	@JoinColumn(name = "id_questionario")
//	@ForeignKey(name = "FK_PERGUNTA_QUESTIONARIO")
	private Questionario questionario;
	
	@Column(name = "descricao")
	private String descricao;
	
	@Column(name = "ordem")
	private Integer ordem;
	
	@OrderBy("ordem")
	@OneToMany(mappedBy = "pergunta", cascade = CascadeType.ALL)
	private Set<Resposta> respostas = new HashSet<Resposta>();
	
	public Pergunta() {
		super();
	}
	
	public Pergunta(Long id) {
		super();
		this.id = id;
	}	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pergunta other = (Pergunta) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Set<Resposta> getRespostas() {
		return respostas;
	}

	public void setRespostas(Set<Resposta> respostas) {
		this.respostas = respostas;
	}

	public void setQuestionario(Questionario questionario) {
		this.questionario = questionario;
	}

	public Questionario getQuestionario() {
		return questionario;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public Integer getOrdem() {
		return ordem;
	}

	public void setOrdem(Integer ordem) {
		this.ordem = ordem;
	}

}
